package DAO;

import java.sql.ResultSet;
import java.util.ArrayList;
import POJO.*;
import Util.MySqlDataAccessHelper;

public class CategoryDAO {
	public static ArrayList<Category> lstCategory() {
		ArrayList<Category> lstCate = new ArrayList<Category>();
		MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
		try {
			String sql = "select category.CategoryID,category.CategoryName,category.PhotoCate from category";
			helper.open_en();
			ResultSet rs = helper.executeQuery(sql);
			while (rs.next()) {
				Category cate = new Category();
				cate.setCategoryId(rs.getInt("CategoryID"));
				cate.setCategoryName(rs.getString("CategoryName"));
				cate.setCategoryPhoto(rs.getString("PhotoCate"));
				lstCate.add(cate);
			}
		} catch (Exception ex) {
			ex.getMessage();
		}
		return lstCate;
	}
	public static ArrayList<Category> lstCategoryid(int idCate) {
		ArrayList<Category> lstCate = new ArrayList<Category>();
		MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
		try {
			String sql = "select category.CategoryID,category.CategoryName,category.PhotoCate  from category where category.CategoryID="+idCate+"";
			helper.open_en();
			ResultSet rs = helper.executeQuery(sql);
			while (rs.next()) {
				Category cate = new Category();
				cate.setCategoryId(rs.getInt("CategoryID"));
				cate.setCategoryName(rs.getString("CategoryName"));
				cate.setCategoryPhoto(rs.getString("PhotoCate"));
				lstCate.add(cate);
			}
		} catch (Exception ex) {
			ex.getMessage();
		}
		return lstCate;
	}
	public static ArrayList<Category> lstCategoryid_index(int idCate) {
		ArrayList<Category> lstCate = new ArrayList<Category>();
		MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
		try {
			String sql = "select category.CategoryName from category where category.CategoryID="+idCate+"";
			helper.open_en();
			ResultSet rs = helper.executeQuery(sql);
			while (rs.next()) {
				Category cate = new Category();
				//cate.setCategoryId(rs.getInt("CategoryID"));
				cate.setCategoryName(rs.getString("CategoryName"));
				//cate.setCategoryPhoto(rs.getString("PhotoCate"));
				lstCate.add(cate);
			}
		} catch (Exception ex) {
			ex.getMessage();
		}
		return lstCate;
	}

}
